package org.bees.cms.web.util.velocity.editer;

import java.io.Serializable;

import net.sf.json.JSONObject;

import org.bees.cms.web.util.Beans;

public class ScreenerEditer extends AbstractClauseEditer {
	private Integer rows = 5;
	private Integer cols = 50;

	@Override
	public void initialize(JSONObject json) throws Exception {
		super.initialize(json);
		rows = json == null ? rows : json.containsKey("rows") ? json.getInt("rows") : rows;
		cols = json == null ? cols : json.containsKey("cols") ? json.getInt("cols") : cols;
	}

	@Override
	public String edit(Serializable t) throws Exception {
		value = t == null ? "" : Beans.getString(t, property);
		StringBuilder builder = new StringBuilder();

		builder.append("<textarea id='" + id + "'");
		builder.append(" class='" + clazz + "'");
		builder.append(" style='" + style + "'");
		builder.append(" name='" + name + "'");
		builder.append(" rows='" + rows + "'");
		builder.append(" cols='" + cols + "'");
		builder.append(" placeholder='" + placeholder + "'");
		builder.append(" readonly='readonly'");
		builder.append(" validator='" + validator + "'");
		builder.append(">");
		builder.append(value);
		builder.append("</textarea>");

		builder.append("<br/>");

		builder.append("<button");
		builder.append(" type='button'");
		builder.append(" onclick=\"javascript:openScreener(this);\"");
		builder.append(" table='" + table + "'");
		builder.append(" name='" + name + "'");
		builder.append(">");
		builder.append("编辑");
		builder.append("</button>");

		return builder.toString();
	}

	@Override
	public void destroy() throws Exception {
		super.destroy();
		rows = null;
		cols = null;
	}

	public Integer getRows() {
		return rows;
	}

	public void setRows(Integer rows) {
		this.rows = rows;
	}

	public Integer getCols() {
		return cols;
	}

	public void setCols(Integer cols) {
		this.cols = cols;
	}

}
